import React, { Component } from "react";
import { Link, Route, Switch, Redirect } from "react-router-dom";

class Home extends Component {
  render() {
    return <div>首页</div>;
  }
}
class About extends Component {
  render() {
    return <div>关于页</div>;
  }
}
class Mine extends Component {
  render() {
    return <div>我的页</div>;
  }
}

// const NotFound = () => {
//   return <div>404 not found...</div>;
// };

class Basic extends Component {
  state = {};
  render() {
    return (
      <>
        <h3>路由404</h3>
        <ul>
          <li>
            <Link to="/home">home</Link>
          </li>
          <li>
            <Link to="/about">about</Link>
          </li>
          <li>
            <Link to="/mine">mine</Link>
          </li>
        </ul>

        <Switch>
          {/* 一定要配合Switch组件，必须要写在最下面 */}
          <Route path="/home" component={Home} exact></Route>
          <Route path="/about" component={About}></Route>
          <Route path="/mine" component={Mine}></Route>
          {/* <Route path="*" component={NotFound}></Route> */}
          <Route
            path="*"
            render={() => {
              return <Redirect to="/home"></Redirect>;
            }}
          ></Route>
        </Switch>
      </>
    );
  }
}

export default Basic;
